//
// UploadJig
//
// Copyright (C) jextra.net.
//
//  This file is part of the Nubbin Library.
//
//  The Nubbin Library is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  The Nubbin Library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with the Nubbin Library; if not, write to the Free
//  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
//  02111-1307 USA.
//

package net.jextra.nubbinstoreweb.jig;

import java.io.*;
import java.net.*;
import net.jextra.crack.tool.*;
import net.jextra.jig.*;

@JigDef( description = "Upload file to NubbinStore." )
public class UploadJig implements Jig
{
    // ============================================================
    // Fields
    // ============================================================

    public static final int BUFFER_SIZE = 10000;

    @JigField( "URL:" )
    private String _url;

    @JigField( "Store path:" )
    private String _storePath;

    @JigField( "File to upload:" )
    private String _fileName;

    // ============================================================
    // Methods
    // ============================================================

    // ----------
    // public
    // ----------

    @JigCommand( "Upload" )
    public void upload()
        throws Exception
    {
        URL url = new URL( _url + "/upload" );
        URLConnection conn = url.openConnection();
        System.out.println( url.toString() );
        HTTPPost post = new HTTPPost( conn );
        post.addParameter( "path", _storePath );
        post.addParameter( "file", new File( _fileName ) );
        post.execute();
    }
}

